package com.popo.java.io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;

public class CoalitionFile {
	public static void main(String[] args) {
		File f = new File("D:/104/芙蓉镇.txt");
		if(!f.exists())
			try {
				f.createNewFile();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		else{
			f.delete();
			try {
				f.createNewFile();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		try {
			BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(f));
			byte[] b =new byte[1024*10];
			int len=0;
			StringBuilder sb  = new StringBuilder("\n\r\n\r------------------------------\n\r\n\r");
			for(int i=1;i<=32;i++){
				BufferedInputStream bi = new BufferedInputStream(new FileInputStream(new File("d:/104/"+i+".txt")));
				try {
					bo.write("\n\n\r".getBytes());
					while((len=bi.read(b))>-1){
						bo.write(b, 0, len);
					}
					bo.write((sb.toString()+"第"+i+"章\n\n\r").getBytes());
				
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}finally{
					try {
						bi.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		
			try {
				bo.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}	
